#ifndef RISKMEASUREEDITOR_H
#define RISKMEASUREEDITOR_H

#include <QObject>
#include <QMap>
#include <QTableView>
#include <QtXml>
#include "ui_mainwindow.h"
#include "riskmeasure/RiskMeasure.h"
#include <iostream> // TODO: remove me

class RiskMeasureEditor : public QObject
{
Q_OBJECT
public:
    explicit RiskMeasureEditor(Ui::MainWindow *ui, QObject *parent = 0);
    void setRiskMeasureRoot(boost::shared_ptr<quic::RiskMeasure> riskMeasureRoot);

signals:

public slots:
    void riskMeasureSelected(const QModelIndex & index);

private slots:
    void nameChanged(const QString & name);
    void attributeChanged(const QString &) {attributeChanged();}

    // Shame slots doesn't allow templates
    void inputName1Changed(const QString &inputName) {inputNameChanged(1, inputName);}
    void inputName2Changed(const QString &inputName) {inputNameChanged(2, inputName);}
    void inputName3Changed(const QString &inputName) {inputNameChanged(3, inputName);}
    void attributeChanged(int) {attributeChanged();}

private:
    Ui::MainWindow *ui;
    QDomDocument riskMeasureConfig;
    QMap<QString,QDomNode> riskMeasureMap;
    QMap<QString,QDomNode> riskMeasureModuleMap;
    boost::shared_ptr<quic::RiskMeasure> riskMeasure;
    QMap<QString,QStringList> inputList;

    void attributeChanged();
    void inputNameChanged(int inputNum, const QString &inputName);
    void setupInputs();
    void setupInput(QComboBox &cmbInputName, QComboBox &cmbInputOutput, int parentIndex);
    void setupRiskMeasureName();
    void setupParameters();
    void indexRiskMeasure(boost::shared_ptr<quic::RiskMeasure> riskMeasure);
};

#endif // RISKMEASUREEDITOR_H
